package com.ae.shield.common.enchantment.shieldSuffix;

import com.ae.shield.common.items.shieldFittings.makers.ShieldMakerBase;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentType;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;

/**
 * 护盾后缀的基础类，继承此类来增加新的后缀
 * 借用原版附魔系统实现后缀
 */
public class SuffixBase extends Enchantment {
    public final float[] intensity;
    public final float[] upperLimit;
    public final float[] floorLimit;
    public final float[] recovery;
    public final float[] close;
    public final float[] remote;
    public final float[] magic;
    public final float[] other;
    public final float[] penalty;
    public final float[] piles;
    public final float[] cost;
    public final float[] cd;

    public SuffixBase() {
        this(new SuffixRate());
    }

    public SuffixBase(SuffixRate rateIn) {
        super(Enchantment.Rarity.COMMON, EnchantmentType.create("SHIELD_MAKER", (item) -> item instanceof ShieldMakerBase), new EquipmentSlotType[]{EquipmentSlotType.OFFHAND});
        intensity = rateIn.intensity;
        upperLimit = rateIn.upperLimit;
        floorLimit = rateIn.floorLimit;
        recovery = rateIn.recovery;
        close = rateIn.close;
        remote = rateIn.remote;
        magic = rateIn.magic;
        other = rateIn.other;
        penalty = rateIn.penalty;
        piles = rateIn.piles;
        cost = rateIn.cost;
        cd = rateIn.cd;
    }

    /**
     * @param level 附魔等级
     * @param property 需要计算的属性
     * @param rate 属性的倍率
     * @return 经过等级放大后的倍率
     */
    public float levelRate(int level, SuffixProperty property, float rate) {
        return rate * level;
    }

    @Override
    public int getMaxLevel() {
        return 1;
    }

    /**
     * 只能被应用于护盾发生器
     */
    @Override
    public boolean canApply(ItemStack stack) {
        return stack.getItem() instanceof ShieldMakerBase;
    }

    /**
     * 无法从村民交易获得
     */
    @Override
    public boolean canVillagerTrade() {
        return false;
    }

    /**
     * 无法通过附魔台获取附魔书
     */
    @Override
    public boolean isAllowedOnBooks() {
        return false;
    }

    /**
     * 从战利品中移除
     */
    @Override
    public boolean canGenerateInLoot() {
        return false;
    }

    /**
     * 无法在附魔台获得
     */
    @Override
    public boolean canApplyAtEnchantingTable(@Nonnull ItemStack stack) {
        return false;
    }

//---------------------------------------------------后缀倍率------------------------------------------------------------

    /**
     * 数组共两个值
     * 第一个值为倍率
     * 第二个值为计算方式，必须是整数
     * 0：增量 1：倍率增量 2：最终倍乘
     */
    public static class SuffixRate {
        private float[] intensity = {0f, 0f};
        private float[] upperLimit = {0f, 0f};
        private float[] floorLimit = {0f, 0f};
        private float[] recovery = {0f, 0f};
        private float[] close = {0f, 0f};
        private float[] remote = {0f, 0f};
        private float[] magic = {0f, 0f};
        private float[] other = {0f, 0f};
        private float[] penalty = {0f, 0f};
        private float[] piles = {0f, 0f};
        private float[] cost = {0f, 0f};
        private float[] cd = {0f, 0f};

        /**
         * 强度消耗倍率
         */
        public SuffixBase.SuffixRate intensity(float rate, int operator) {
            intensity = new float[]{rate, operator};
            return this;
        }

        /**
         * 承受上限倍率
         */
        public SuffixBase.SuffixRate upper(float rate, int operator) {
            upperLimit = new float[]{rate, operator};
            return this;
        }

        /**
         * 触发下线倍率
         */
        public SuffixBase.SuffixRate floor(float rate, int operator) {
            floorLimit = new float[]{rate, operator};
            return this;
        }

        /**
         * 恢复倍率
         */
        public SuffixBase.SuffixRate recovery(float rate, int operator) {
            recovery = new float[]{rate, operator};
            return this;
        }

        /**
         * 近战消耗倍率
         */
        public SuffixBase.SuffixRate close(float rate, int operator) {
            close = new float[]{rate, operator};
            return this;
        }

        /**
         * 远程消耗倍率
         */
        public SuffixBase.SuffixRate remote(float rate, int operator) {
            remote = new float[]{rate, operator};
            return this;
        }

        /**
         * 魔法消耗倍率
         */
        public SuffixBase.SuffixRate magic(float rate, int operator) {
            magic = new float[]{rate, operator};
            return this;
        }

        /**
         * 其他消耗倍率
         */
        public SuffixBase.SuffixRate other(float rate, int operator) {
            other = new float[]{rate, operator};
            return this;
        }

        /**
         * 惩罚倍率
         */
        public SuffixBase.SuffixRate penalty(float rate, int operator) {
            penalty = new float[]{rate, operator};
            return this;
        }

        /**
         * 护盾消耗倍率
         */
        public SuffixBase.SuffixRate piles(float rate, int operator) {
            piles = new float[]{rate, operator};
            return this;
        }

        /**
         * 单次恢复的消耗倍率
         */
        public SuffixBase.SuffixRate cost(float rate, int operator) {
            cost = new float[]{rate, operator};
            return this;
        }

        /**
         * 冷却时间的倍率
         */
        public SuffixBase.SuffixRate cd(float rate, int operator) {
            cd = new float[]{rate, operator};
            return this;
        }
    }
}
